package com.mapapp.flutter_mapapp.widget;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.TextView;

import com.mapapp.flutter_mapapp.R;

import razerdp.basepopup.BasePopupWindow;

public class SurveyOptionsDialog extends BasePopupWindow {

    private TextView surveyAdd;
    private TextView surveyUpdate;
    private TextView surveyReplace;
    private CardView cvOk;


    public SurveyOptionsDialog(Context context) {
        super(context);


        init();
    }

    @Override
    public View onCreateContentView() {
        View view = createPopupById(R.layout.dialog_survey_options);
        surveyAdd = view.findViewById(R.id.survey_add);
        surveyUpdate = view.findViewById(R.id.survey_update);
        surveyReplace = view.findViewById(R.id.survey_replace);
        cvOk = view.findViewById(R.id.cv_ok);
        return view;
    }

    private void init() {
        //默认一个
        surveyAdd.setSelected(true);
        surveyAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                surveyAdd.setSelected(true);
                surveyUpdate.setSelected(false);
                surveyReplace.setSelected(false);
            }
        });

        surveyUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                surveyAdd.setSelected(false);
                surveyUpdate.setSelected(true);
                surveyReplace.setSelected(false);
            }
        });

        surveyReplace.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                surveyAdd.setSelected(false);
                surveyUpdate.setSelected(false);
                surveyReplace.setSelected(true);
            }
        });

        cvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(getType());
                }
                dismiss();
            }
        });

    }

    private int getType() {
        //0 新增；1 修改；2 覆盖
        return surveyAdd.isSelected() ? 0 : surveyUpdate.isSelected() ? 1 : 2;
    }


    public interface OnItemClickListener {
        void onClick(int type);
    }

    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }
}
